package eu.web.permission;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 权限
 * 
 * @author WZZ
 * 
 */
class Access {

	String path;

	List<String> powers = new ArrayList<String>();

	Access(String path, String powers) {
		this.path = path;
		if (powers == null || powers.length() == 0
				|| "null".equalsIgnoreCase(powers))
			powers = null;
		else
			for (String power : powers.split(",")) {
				power = power.trim();
				if ("null".equalsIgnoreCase(power))
					powers = null;
				this.powers.add(power);
			}
	}

	public boolean validate(Set<String> powers) {
		if (this.powers != null && !this.powers.isEmpty()) {
			if (powers == null || powers.isEmpty())
				return false;
			for (String power : this.powers) {
				if (!powers.contains(power))
					return false;
			}
		}
		return true;
	}

}
